/*
 * Copyright (C) 2008 Peter Kling
 *
 * This file is part of 'A Kind of Billiard', a graphical billiard simulation.
 *
 * 'A Kind of Billiard' is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 *
 * 'A Kind of Billiard' is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * 'A Kind of Billiard'. If not, see <http://www.gnu.org/licenses/>.
 */

package cg2.billiard;

import javax.media.opengl.GL;

import cg2.misc.OpenGLDrawable;
import cg2.models.GLModel;
import cg2.physics.PhysicalBall;

import com.sun.opengl.util.GLUT;

/**
 * @brief A billiard ball.
 * 
 * Can be drawn using OpenGL.
 */
public class BilliardBall extends PhysicalBall implements OpenGLDrawable {
	private GLModel model;
	GLUT glut;
	
	/**
	 * @brief Constructs a billiard ball of the specified mass and radius.
	 * 
	 * See class Billiard for some default values for mass and radius.
	 * 
	 * @see Billiard
	 */
	public BilliardBall(double mass, double radius) {
		super(mass, radius);
		setFrictionCoefficient(Billiard.BILLIARDBALL_FRICTIONCOEFFICIENT);
		glut = new GLUT();
	}

	/**
	 * @brief OpenGL method to draw the billiard ball.
	 */
	public void draw(GL gl) {
		gl.glPushMatrix();
		gl.glTranslated(position.get(0), position.get(1), position.get(2));
		gl.glMultMatrixd(orientation.getData(), 0);
		if (model != null) {
			model.draw(gl);
		} else {
			glut.glutSolidSphere(radius, 25, 25);
		}
		gl.glPopMatrix();
	}

	
	/**
	 * @brief Sets the model for the ball.
	 * 
	 * If no model is specified (that is if model is null), a ball using the current OpenGL color is drawn.
	 */
	public void setModel(GLModel model) {
		this.model = model;
	}
}
